//
//  LoginViewController.swift
//  二次源
//
//  Created by 李建文 on 2016/10/16.
//  Copyright © 2016年 二次源. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {

    let db:dbController = dbController()

    @IBOutlet weak var id: UITextField!
    
    @IBOutlet weak var pwd: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        pwd.keyboardType = .default
        id.returnKeyType = .done
        pwd.returnKeyType = .done
    }

    @IBAction func inputId(_ sender: AnyObject) {
        id.resignFirstResponder()
    }
    
    @IBAction func inputPwd(_ sender: AnyObject) {
        pwd.resignFirstResponder()
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func didCancel(_ sender: AnyObject) {
       db.deleAll()
       self.dismiss(animated: true, completion:nil)  
    }
    
   
 
    @IBAction func didLogin(_ sender: AnyObject) {
        if(id.text=="1"&&pwd.text=="1"){
            db.saveUser(uname: "test", uid: "1")
            print(db.getUserName())
            self.dismiss(animated: true , completion:nil)
        }else{
            db.deleAll();
            id.text=""
            pwd.text=""
            let alertController = UIAlertController(title: "系统提示",
                                                    message: "您输入的账号密码有误", preferredStyle: .alert)
            let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
            let okAction = UIAlertAction(title: "好的", style: .default, handler: {
                action in
                print("点击了确定")
            })
            alertController.addAction(cancelAction)
            alertController.addAction(okAction)
            self.present(alertController, animated: true, completion: nil)
        }
      
    }
   

}
